module.exports = function() {
    return async (ctx, next) => {
        
        ctx.response.set('Access-control-Allow-Origin', '*');
        // ctx.set("Access-Control-Allow-Origin", "http://localhost:8080"); // 只允许指定域名http://localhost:8080的请求
        ctx.response.set('Access-Control-Allow-Methods', 'OPTIONS, GET, PUT, POST, DELETE');
        ctx.response.set('Access-Control-Allow-Headers', '*' );// ctx.request.header['access-control-request-headers']
    
        if (ctx.method == 'OPTIONS') {
            ctx.response.status = 204
            ctx.response.body = ''
        } else {
            await next()
        }
    }
 }